/*设备注册操作类
Created on 2020年05月10日
@author: zxyong 13738196011
 */

package com.zxy.business;

import java.sql.ResultSet;

import com.zxy.common.Com_Fun;
import com.zxy.db_Self.*;

public class Ope_DB_Go
{
	public void Set_Reg_Device(StringBuilder strInfo,String DEVICE_IP,String DEVICE_PORT)
	{
		String DEVICE_CODE = "";
		String DEVICE_NAME = "";
		for(String strs: strInfo.toString().replace("@##","").replace("##@","").split("&"))
		{
			if(strs.split("=").length > 1)
			{
				if(strs.split("=")[0].equals("CHILD_NODE"))
					DEVICE_CODE = strs.split("=")[1];
				if(strs.split("=")[0].equals("DEVICE_NAME"))
					DEVICE_NAME = strs.split("=")[1];
			}
		}
		Db_Common_Self dbc_ic = new Db_Common_Self();
		StringBuilder strSql = new StringBuilder();
		try
		{
			if(DEVICE_CODE.length() > 10)
			{
				strSql.append("select * from t_reg_device where DEVICE_CODE = '" + DEVICE_CODE + "'");
				ResultSet rs = dbc_ic.Common_Sql(strSql);
				boolean bFlag = false;
				while(rs.next())
				{
					bFlag = true;
					break;
				}
				if(bFlag)
				{
					strSql.delete(0,strSql.length());
					strSql.append("update t_reg_device set DEVICE_NAME = '" + DEVICE_NAME + "',DEVICE_IP='" + DEVICE_IP + "',DEVICE_PORT='" + DEVICE_PORT + "',DEVICE_STATE='1'," + " DEVICE_TIME = '" + Com_Fun.DateTimeStr("yyyy-MM-dd HH:mm:ss") + "' where DEVICE_CODE = '" + DEVICE_CODE + "'");
				}
				else
				{
					strSql.delete(0,strSql.length());
					strSql.append("insert into t_reg_device(DEVICE_CODE,DEVICE_NAME,DEVICE_IP," + "DEVICE_PORT,DEVICE_STATE,DEVICE_TIME,S_DESC,CREATE_DATE) values('" + DEVICE_CODE + "','" + DEVICE_NAME + "','" + DEVICE_IP + "','" + DEVICE_PORT + "','1','" + Com_Fun.DateTimeStr("yyyy-MM-dd HH:mm:ss") + "','','" + Com_Fun.DateTimeStr("yyyy-MM-dd HH:mm:ss") + "');");
				}
				dbc_ic.CommonExec_Sql(strSql);
			}
		}
		catch(Exception e)
		{
		}
		finally
		{
			if(dbc_ic != null)
			{
				dbc_ic.conn_a.returnConnection();
			}
		}
	}
}